﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using KZ.Exception;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;
using KZ.Utilities;

namespace KZ.Lottery.DAL
{
    public class GroupValueDAL
    {
        private static GroupValue CreateGroupValueFromReader(SqlDataReader reader)
        {
            GroupValue groupValue = new GroupValue
            {
                GroupID = Utility.StringParse(reader[GroupValueColumns.GroupID.ToString()]),
                Value = Utility.StringParse(reader[GroupValueColumns.Value.ToString()]),
            };

            return groupValue;
        }

        public static List<GroupValue> GetGroupValueList()
        {
            try
            {
                List<GroupValue> groupValueList = new List<GroupValue>();

                using (SqlDataReader reader = DataAccessHelper.ExecuteQuery(CommandType.StoredProcedure, KZ_StoreName.GroupValueGetList))
                {
                    while (reader.Read())
                    {
                        groupValueList.Add(CreateGroupValueFromReader(reader));
                    }
                }

                return groupValueList;
            }
            catch (SqlException ex)
            {
                Log.LogEx("GetGroupValueList", ex);
                throw new DataAccessException(KZ_Message.BLM_ERR_GROUPVALUE_GETLIST);
            }
        }
    }
}